import json
import os

class ConfigReader:
    def __init__(self, config_file="data/config.json"):
        self.config_file = config_file
        self.config = self._load_config()
    
    def _load_config(self):
        """加载配置文件"""
        if os.path.exists(self.config_file):
            with open(self.config_file, 'r', encoding='utf-8') as f:
                return json.load(f)
        else:
            return {
                "browser": "edge",
                "headless": True,
                "timeout": 30,
                "implicit_wait": 10
            }
    
    def get_bmc_config(self, bmc_name):
        """获取单台机器的BMC配置"""
        bmcs = self.config.get("bmcs", {})
        return bmcs.get(bmc_name, {})
    
    def get_all_bmcs(self):
        """获取所有BMC配置"""
        return self.config.get("bmcs", {})
    
    def get_outofban_server(self):
        """获取带外服务器的配置"""
        return self.config.get("os_outofband_server")
    
    def get_hw_moniter_num(self):
        """获取所有hw的数量"""
        return self.config.get("hw_moniter_num")

    def get_hw_moniter_id(self):
        """获取所有hw的xpath id"""
        return self.config.get("hw_moniter_id")
    
    def get_asset_hw_tag(self):
        """获取所有hw的tag"""
        return self.config.get("asset_hw_tag")

    def get_asset_hw_infos(self):
        """获取所有hw的信息"""
        return self.config.get("asset_hw_infos")